home *** CD-ROM | disk | FTP | other *** search
/ CD ROM Paradise Collection 4 / CD ROM Paradise Collection 4 1995 Nov.iso / program / swagd_f.zip / DATETIME.SWG / 0027_What is NEXT day ??.pas < prev    next >
Pascal/Delphi Source File  |  1993-10-28  |  2KB  |  40 lines

  1. {===========================================================================
  2. Date: 10-04-93 (12:39)
  3. From: ANDREW KEY
  4. Subj: What is NEXT day ??
  5. ---------------------------------------------------------------------------
  6.  AC> My assignment is to write a program, given three integers whose values
  7.  AC> represent a day between January 1, 1900 and December 30, 1999, will
  8.  AC> output the value representing the day following.
  9.  
  10.  AC> I am running into problems with three things.  The end of a month, the
  11.  AC> end of a year, and leap years.
  12.  
  13. Here's a procedure you might get some ideas from... }
  14.  
  15. procedure NextDay(var MM,DD,YYYY: integer);
  16.   const
  17.     DaysInMonth: array[0..1,1..12] of integer =
  18.       ((31,28,31,30,31,30,31,31,30,31,30,31),   {regular year}
  19.        (31,29,31,30,31,30,31,31,30,31,30,31));  {leap year}
  20.   var
  21.     Leap: integer;
  22.   begin
  23.     Inc(DD);                            {increment day}
  24.     if (YYYY mod 4) = 0 then            {is it a leap year?}
  25.       Leap:=1                           {Leap year}
  26.     else
  27.       Leap:=0;                          {non-leap year}
  28.     if DD>DaysInMonth[Leap,MM] then     {is DD > the end of the month?}
  29.       begin
  30.         DD:=1;                          {set to 1st of month}
  31.         Inc(MM);                        {increment month by one}
  32.         if MM>12 then                   {is MM > December?}
  33.           begin
  34.             MM:=1;                      {set MM to January}
  35.             Inc(YYYY);                  {and increment YYYY}
  36.           end; {if MM>12}
  37.       end; {if DD>Days}
  38.   end; {proc NextDay}
  39.  
  40.